// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <cantor/unresolved/visitor.h>
#include <turbo/log/logging.h>
#include <cantor/unresolved/clause/algorithm_opt.h>
#include <cantor/unresolved/clause/index_lock_opt.h>

namespace cantor::unresolved {

    class UnresolvedDispatchExpr;

    class UnresolvedIndexOption : public UnresolvedVisitor<UnresolvedIndexOption> {
    public:
        static constexpr const cantor::pb::ast::ExprNodeType TYPE = cantor::pb::ast::ExprNodeType::ENT_INDEX_OPT;

        UnresolvedIndexOption(const cantor::pb::ast::IndexOption &node) : instance(node) {
        }

        ~UnresolvedIndexOption() override = default;

        const pb::Location& location_impl() const {
            return  instance.location();
        }

        const pb::Status &error_status_impl() const {
            return  instance.status();
        }

        std::string_view comment() const {
            if (!instance.has_comment()) {
                return std::string_view{};
            }
            return instance.comment();
        }

        cantor::pb::ast::IndexAlgoType index_type() const {
            return instance.index_type();
        }

        std::string index_type_str() const {
            return cantor::pb::ast::IndexAlgoType_Name(index_type());
        }

        bool has_algorithm() const {
            return instance.has_algo();
        }

        UnresolvedAlgorithmOpt algorithm() const {
            KCHECK(instance.has_algo());
            return UnresolvedAlgorithmOpt(instance.algo());
        }

        bool has_index_lock() const {
            return instance.has_lock();
        }

        UnresolvedIndexLockOpt index_lock() const {
            KCHECK(instance.has_lock());
            return UnresolvedIndexLockOpt(instance.lock());
        }

        const cantor::pb::ast::IndexOption &instance;
    };
} // namespace cantor::unresolved
